|
|
|
|
|
|
|
End If
* If the last name was not entered then display an error message
* to the user and exit the routine
If Len(txtLastName) = 0 Then
Screen.MousePointer = VBDefault
MsgBox You Must Enter a First and Last Name., VBExclamation, _ App.Title
Exit Sub
End If
* if you got this far update the record.
datLogEntry.Recordset.Update
intEntryKey = datLogEntry.Recordset.Fields(cdt_id).Value
Screen.MousePointer = VBDefault
End Sub |
|
|
|
|
|
|
|
|
As you can see from this final version of the routine, the code becomes very easy to follow. Related IfEnd If statements are easy to spot, and the comment box explains the routine's overall purpose. |
|
|
|
|
|
|
|
|
In the routine, notice that two variables are globalmeaning that they were defined outside the routine. The scope of your objects, constants, and variables are important. They should always be defined with the smallest scope possible. Global variables can make the logic of an application extremely difficult to follow. They also make it much more difficult to reuse functions or subprograms in other applications. The concept of scoping is covered later in this book. |
|
|
|
|
|
|
|
|
After you start coding your application, you need to start the process of testing the code to see whether it works and to fix or debug the code that doesn't. Not everyone tests as thoroughly as they should; this is demonstrated by all the fixes and upgrades to existing software. Then again, no matter how much you test, there will always be bugs that you didn't find. In addition to bugs that you didn't find in the first place are bugs introduced into an application whenever changes or other fixes are applied to the code. To prevent much of these types of bugs, you should do what's called regression testingretesting everything that has been tested before. |
|
|
|
|
|
|
|
|
You'll actually be doing two levels of testing: |
|
|
|
|
|
|
|
|
Unit testingtesting individual routines or sections of code. An example of this would be to test just the code for the data-entry routine and nothing else. |
|
|
|
|
|
|
|
|
Integration testingtesting all the different units as a single system. |
|
|
|
|
|
|
|
|
When testing your application, try not to use data or input that you know will work. The real art in testing is to pick test data that most likely will cause errors. You also can try the what-if method: Ask yourself what would happen if the user does something |
|
|
|
|
|